package A_review.review9_4;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

public class Class39 {
//TODO:2023/9/4  candidates 不含重复的元素
    List<List<Integer>> result = new ArrayList<>();
    LinkedList<Integer> path = new LinkedList<>();
    int curSum = 0;

    void find(int[]  candidates, int target) {

//        Arrays.sort(candidates);
        backing(candidates,0,target,curSum);

    }


    void backing(int[] candidates,int start, int target, int curSum) {
        if (curSum > target) {
            return;
        }
        if ( curSum ==target) {
            result.add(new ArrayList<>(path));
            return;
        }
        for (int i = start; i <candidates.length; i++) {
            curSum += candidates[i];
            path.add(candidates[i]);

            //TODO:2023/9/4  就这点和其他的不同呢
            backing(candidates,i,target,curSum);
            path.remove(path.size() - 1);
            curSum -= candidates[i];
        }

    }

    public static void main(String[] args) {
        Class39 class39 = new Class39();
        int[]  cur={2,3,5};
        class39.find(cur,8);
        System.out.println(class39.result.toString());


    }

}
